﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Evan.SystemLog
{
    /// <summary>
    /// 系统日志 写入数据库的
    /// </summary>
    public static class SysLog
    {
        //public static void AddSysLog(DataBase.DbOperat DbOperat, Model.SysModel.SystemLog SysLogs)
        //{
        //    dynamic Model = new Evan.Model.DynamicModel();
        //    Model.Set("UserId", SysLogs.UserId);
        //    Model.Set("UserName", SysLogs.UserName);
        //    Model.Set("AddTime", DateTime.Now); //默认当前时间
        //    Model.Set("UserIP", Common.IPHelper.GetHostAddress());
        //    Model.Set("IPAddress", Common.IPHelper.GetHostAddress());
        //    Model.Set("Title", SysLogs.Title);
        //    Model.Set("Content", SysLogs.Content);
        //    Model.Set("Ver", ""); //版本默认为空吧
        //    Model.Set("IsOpeart", "1"); //默认所有都是操作日志
        //    Model.Set("States", "1"); //默认都可以看到
        //    DbOperat.InsertReturnId(Model);
        //}

        /// <summary>
        ///  添加系统日志 其余由系统补充
        /// </summary>
        /// <param name="DbOperat"></param>
        /// <param name="Title"></param>
        /// <param name="Cont"></param>
        public static void AddSysLog(DataBase.DbOperat DbOperat, string Title, string Cont)
        {
            dynamic Model = new Evan.Model.DynamicModel();
            Model.Set("UserId", Member.Administrator.GetAdminId());
            Model.Set("UserName", Member.Administrator.GetAdminName());
            Model.Set("AddTime", DateTime.Now); //默认当前时间
            Model.Set("UserIP", Common.IPHelper.GetHostAddress());
            Model.Set("IPAddress", Common.IPHelper.GetHostAddress());
            Model.Set("Title", Title);
            Model.Set("Content", Cont);
            Model.Set("Ver", ""); //版本默认为空吧
            Model.Set("IsOpeart", "1"); //默认所有都是操作日志
            Model.Set("States", "1"); //默认都可以看到
            DbOperat.InsertReturnId(Model);
        }
        ///// <summary>
        ///// 添加系统日志
        ///// </summary>
        ///// <param name="SysLogs">系统日志的Model</param>
        //public static void AddSysLog(Model.SysModel.SystemLog SysLogs)
        //{
        //    dynamic Model = new Evan.Model.DynamicModel();
        //    Model.Set("UserId", Member.Administrator.GetAdminId());
        //    Model.Set("UserName", Member.Administrator.GetAdminName());
        //    Model.Set("AddTime", DateTime.Now); //默认当前时间
        //    Model.Set("UserIP", Common.IPHelper.GetHostAddress());
        //    Model.Set("IPAddress", Common.IPHelper.GetHostAddress());
        //    Model.Set("Title", SysLogs.Title);
        //    Model.Set("Content", SysLogs.Content);
        //    Model.Set("Ver", ""); //版本默认为空吧
        //    Model.Set("IsOpeart", "1"); //默认所有都是操作日志
        //    Model.Set("States", "1"); //默认都可以看到
        //    new DataBase.DbOperat("SystemLog").InsertReturnId(Model);
        //}

        /// <summary>
        /// 添加系统日志 其余由系统补充
        /// </summary>
        /// <param name="Title">标题</param>
        /// <param name="Cont">内容</param>
        public static void AddSysLog(string Title, string Cont)
        {
            dynamic Model = new Evan.Model.DynamicModel();
            Model.Set("UserId", Member.Administrator.GetAdminId());
            Model.Set("UserName", Member.Administrator.GetAdminName());
            Model.Set("AddTime", DateTime.Now); //默认当前时间
            Model.Set("UserIP", Common.IPHelper.GetHostAddress());
            Model.Set("IPAddress", Common.IPHelper.GetHostAddress());
            Model.Set("Title", Title);
            Model.Set("Content", Cont);
            Model.Set("Ver", ""); //版本默认为空吧
            Model.Set("IsOpeart", "1"); //默认所有都是操作日志
            Model.Set("States", "1"); //默认都可以看到
            new DataBase.DbOperat("SystemLog").InsertReturnId(Model);
        }

        /// <summary>
        /// 添加系统日志 其余由系统补充
        /// </summary>
        /// <param name="Title"></param>
        /// <param name="Cont"></param>
        /// <param name="BakContent">JSON字符</param>
        public static void AddSysLog(string Title, string Cont,string BakContent)
        {
            dynamic Model = new Evan.Model.DynamicModel();
            Model.Set("UserId", Member.Administrator.GetAdminId());
            Model.Set("UserName", Member.Administrator.GetAdminName());
            Model.Set("AddTime", DateTime.Now); //默认当前时间
            Model.Set("UserIP", Common.IPHelper.GetHostAddress());
            Model.Set("IPAddress", Common.IPHelper.GetHostAddress());
            Model.Set("Title", Title);
            Model.Set("Content", Cont);
            Model.Set("Ver", ""); //版本默认为空吧
            Model.Set("IsOpeart", "1"); //默认所有都是操作日志
            Model.Set("States", "1"); //默认都可以看到
            BakContent = Common.TransCode.StrDeCode(BakContent);
            Model.Set("BakContent", string.IsNullOrEmpty(BakContent) ? "" : BakContent); //修改或添加内容
            new DataBase.DbOperat("SystemLog").InsertReturnId(Model);
        }

        /// <summary>
        /// 添加系统日志 其余由系统补充
        /// </summary>
        /// <param name="Title"></param>
        /// <param name="Cont"></param>
        /// <param name="BakContent">动态类 , 最后还是转换为JSON字符串</param>
        public static void AddSysLog(string Title, string Cont, dynamic BakContent)
        {
            string bakStr = Model.ConvertModel.ConvertToJson(BakContent);
            AddSysLog(Title, Cont, bakStr);
        }

    }
}
